using System;

namespace RSteel.Utils
{
    public class Utils
    {
        public Utils()
        {
        }

        public static string WrapString(string text, int maxLength)
        {
            int length = text.Length;
            if (maxLength < 0 || maxLength > length)
            {
                return text;
            }
            else
            {
                if (!Char.IsSeparator(text[maxLength - 1]))
                {
                    int ind = length - 2;
                    while (ind >= 0)
                    {
                        if (Char.IsSeparator(text[ind]))
                        {
                            return text.Substring(0, ind + 1);
                        }
                        ind--;
                    }

                    return string.Empty;
                }
                else
                {
                    return text.Substring(0, maxLength);
                }
            }
        }
    }
}